package com.alex.web.db.dao;

import com.alex.web.bean.BaseEntity;
//import com.alex.web.log.MISILogger;
//import com.alex.web.log.MISILoggerFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import javax.annotation.Resource;
import java.lang.reflect.ParameterizedType;
import java.util.List;

public class ReportDao<M extends BaseEntity> extends SqlSessionDaoSupport implements IReportDao<M> {

//    private final MISILogger logger = MISILoggerFactory.getLogger(this.getClass());


    private Class<M> curClassType = null;

    @Resource
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    public String getMapperNameSpace() {
        return curClassType.getName();
    }

    public ReportDao() {
        if (getClass().getGenericSuperclass() instanceof ParameterizedType) {
            curClassType = (Class<M>)((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
        }
    }

    @Override
    public M getEntityBySelectSum(Object parameter) {

        return this.getSqlSession().selectOne(this.getMapperNameSpace()+".SelectSum",parameter);

    }

    @Override
    public List<M> getListByName(String selectId, Object parameter) {
        return this.getSqlSession().selectList(this.getMapperNameSpace()+"."+selectId,parameter);
    }


}
